class Solution:
    def singleNumber(self, nums: list) -> int:
        try:
            while nums:
                mid = nums.pop(-1)
                nums.remove(mid)
        except:
            return mid


class Solution2:
    def singleNumber(self, nums: list) -> int:
        """^表示异或,0与任意数异或为0,两数相同异或为0,异或满足交换律"""
        res = 0
        for i in nums:
            res ^= i
        return res


a = Solution2()
print(a.singleNumber([2, 2, 1]))
print(a.singleNumber([5, 4, 1, 2, 5, 1, 2]))
print(a.singleNumber([1]))
